// 是否为chrome页签
function isChromeTabUrl(url) {
    return url && url.indexOf('chrome://') === 0;
}

chrome.storage.local.remove(['validateResult']);

// 刷新页面
chrome.tabs.query({}, (tabsList) => {
    for (const tab of tabsList) {
        if (!isChromeTabUrl(tab.url)) {
            chrome.tabs.reload(tab.id, {});
        }
    }
});

// 如果没有先onMessage就去sendMessage就会报错
function onMessage(message, sender, sendResponse) {
    try {
        if (message?.action === 'keep_alive') {
            console.log('Service Worker 活跃中');
            sendResponse({
                action: 'keep_alive',
                msg: '唤醒休眠的service_worker',
            });
        }
        return true;
    } catch (error) {
        console.error('Error processing message:', error);
    }
}

chrome.runtime.onMessage.addListener(onMessage);
